package com.trkj.service.hjj;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.hjj.HolidayDAO;
import com.alibaba.fastjson.JSONArray;
import com.trkj.dao.hjj.AffaircategoryDAO;
import com.trkj.dao.hjj.ConfirmaffairDAO;
import com.trkj.dao.hjj.Transaction_categoryDAO;
import com.trkj.dao.wdm.StaffInformationDAO;
import com.trkj.mybatisdao.OpertionDAOI;
import com.trkj.pojo.Affaircategory;
import com.trkj.pojo.Confirmaffair;
import com.trkj.pojo.Holiday;
import com.trkj.pojo.Leaveconfirm;
import com.trkj.pojo.StaffInformation;
import com.trkj.vo.Leaveaddvo;
import com.trkj.vo.Optionsvo;

@Service
//确认事务中心
@Transactional(rollbackFor=Exception.class)
public class Operationservice {
	@Autowired
	private ConfirmaffairDAO confirmaffairDAO;
	@Autowired
	private StaffInformationDAO staffInformationDAO;
	@Autowired
	private HolidayDAO holidayDAO;
	@Autowired
	private AffaircategoryDAO affaircategoryDAO;
	@Autowired
	private OpertionDAOI opertionDAO;
	/**
	 * 获取假种全部名称
	 * @return
	 */
	public List<Holiday> selectAll_holidy(){
		return (List<Holiday>) holidayDAO.findAll();
	}
	
	/**
	 * 获取全部名称
	 * @return
	 */
	public List<Affaircategory> selectAll_holidys(){
		return (List<Affaircategory>) affaircategoryDAO.findalls();
	}
	/**
	 * 获取假种无名称
	 * @return
	 */
	public List<Holiday> selectAll_holidyno(){
		return (List<Holiday>) holidayDAO.findAllno();
	}
	/**
	 * 获取事务类别类型请假
	 * @return
	 */
	public List<Affaircategory> selectAll_affca(){
		return (List<Affaircategory>) affaircategoryDAO.findalltype();
	}
	/**
	 * 获取事务类别类型补班
	 * @return
	 */
	public List<Affaircategory> selectAll_buban(){
		return (List<Affaircategory>) affaircategoryDAO.findalltypebuban();
	}
	/**
	 * 获取事务类别类型外勤
	 * @return
	 */
	public List<Affaircategory> selectAll_waiqin(){
		return (List<Affaircategory>) affaircategoryDAO.findalltypewaiqin();
	}
	/**
	 * 获取事务类别类型加班
	 * @return
	 */
	public List<Affaircategory> selectAll_jiaban(){
		return (List<Affaircategory>) affaircategoryDAO.findalltypejiaban();
	}
	/**
	 * 获取事务类别类型调休
	 * @return
	 */
	public List<Affaircategory> selectAll_tiaoxiu(){
		return (List<Affaircategory>) affaircategoryDAO.findalltypetiaoxiu();
	}
	/**
	 * 获取事务类别类型补卡
	 * @return
	 */
	public List<Affaircategory> selectAll_buka(){
		return (List<Affaircategory>) affaircategoryDAO.findalltypebuka();
	}
	/**
	 * 获取总事务类别总记录条数
	 * @return
	 */
	public long attByPageCount() {
		return confirmaffairDAO.count();
	}
	/**
	 * 获取员工总记录条数
	 * @return
	 */
	public long attByPageCounts() {
		return staffInformationDAO.count();
	}
	/**
	 * 查询所有信息
	 * @return
	 */
	public JSONArray selectAll_opton(){
		return opertionDAO.findAllConfirmaffair();
	}
	//查询所有的事物类型
	public JSONArray findAllAffaitcategory(){
		return opertionDAO.findAllAffaitcategory();
	}
	
	/**
	 * 按照事物类别查询
	 */
	public JSONArray findconFAIRMAFFAIR_SW(String affcaType){
		return opertionDAO.findconFAIRMAFFAIR_SW(affcaType);
	}
	/**
	 * 按照员工的名字模糊搜索
	 */
	public JSONArray findFairmaffair_Mohu(String stainName){
		return opertionDAO.findFairmaffair_Mohu("%"+stainName+"%");
	}
	/**
	 * 请假确认新增
	 * @param option
	 */
	public void optionadd(Optionsvo option){
		StaffInformation staffinfor=staffInformationDAO.findOne(option.getStainId());
		Holiday holiday=holidayDAO.findOne(option.getHolidayId());
		Affaircategory aff=affaircategoryDAO.findOne(option.getAffcaId());
		Confirmaffair leave =  new Confirmaffair();
		leave.setHoliday(holiday);
		leave.setAffaircategory(aff);
		leave.setStaffInformation(staffinfor);
		leave.setConaffStartdate(option.getConaffStartdate());
		leave.setConaffEndtdate(option.getConaffEndtdate());
		leave.setConaffReason(option.getConaffReason());
		confirmaffairDAO.save(leave);

	} 
	/**
	 * 补班确认新增
	 * @param option
	 */
	public void optionbubanadd(Optionsvo option){
		StaffInformation staffinfor=staffInformationDAO.findOne(option.getStainId());
		Affaircategory aff=affaircategoryDAO.findOne(option.getAffcaId());
		Holiday holiday=holidayDAO.findOne(option.getHolidayId());
		Confirmaffair leave =  new Confirmaffair();
		leave.setAffaircategory(aff);
		leave.setHoliday(holiday);
		leave.setStaffInformation(staffinfor);
		leave.setConaffStartdate(option.getConaffStartdate());
		leave.setConaffEndtdate(option.getConaffEndtdate());
		leave.setConaffReason(option.getConaffReason());
		confirmaffairDAO.save(leave);
	} 
	/**
	 * 外勤确认新增
	 * @param option
	 */
	public void optionwaiqinadd(Optionsvo option){
		StaffInformation staffinfor=staffInformationDAO.findOne(option.getStainId());
		Affaircategory aff=affaircategoryDAO.findOne(option.getAffcaId());
		Holiday holiday=holidayDAO.findOne(option.getHolidayId());
		Confirmaffair leave =  new Confirmaffair();
		leave.setAffaircategory(aff);
		leave.setHoliday(holiday);
		leave.setStaffInformation(staffinfor);
		leave.setConaffStartdate(option.getConaffStartdate());
		leave.setConaffEndtdate(option.getConaffEndtdate());
		leave.setConaffReason(option.getConaffReason());
		confirmaffairDAO.save(leave);
	} 
	/**
	 * 清单查找小表格
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<StaffInformation> selectAll_qindancz(int page, int rows){
		return (List<StaffInformation>) staffInformationDAO.findAllqindan(new PageRequest(page - 1, rows));
	}
	/**
	 * 编辑
	 * @param leavo
	 */
	public void optionsupdate(Long  stainId,String stainName,Long holidayId,Long affcaId,Long conaffId,Timestamp conaffEndtdate,Timestamp conaffStartdate,String affcaType,String conaffReason){
		StaffInformation staffinfor=staffInformationDAO.findOne(stainId);
		Holiday holiday=holidayDAO.findOne(holidayId);
		Affaircategory sff=affaircategoryDAO.findOne(affcaId);
		Confirmaffair leave =confirmaffairDAO.findOne(conaffId);
		leave.setHoliday(holiday);
		leave.setStaffInformation(staffinfor);
		leave.setAffaircategory(sff);
		leave.setConaffEndtdate(conaffEndtdate);
		leave.setConaffStartdate(conaffStartdate);
		leave.setConaffReason(conaffReason);
		confirmaffairDAO.save(leave);

	}
	/**
	 * 删除
	 * @param 
	 * @return
	 */
	public void Sales(Long 	conaffId){
		confirmaffairDAO.delete(conaffId);
	}
}
